<?php

/**
 * This is the model class for table "form_thong_bao_moi_thau".
 *
 * The followings are the available columns in table 'form_thong_bao_moi_thau':
 * @property string $id
 * @property string $ten_goi_thau
 * @property integer $nganh
 * @property integer $linh_vuc
 * @property string $dia_diem
 * @property string $ten_du_an
 * @property string $nguon_von
 * @property string $ben_moi_thau
 * @property integer $hinh_thuc
 * @property string $thoi_gian_bat_dau
 * @property string $thoi_gian_ket_thuc
 * @property string $ngay_chinh_sua
 * @property string $dia_diem_ban
 * @property string $gia_ban
 * @property string $thoi_gian_dong_thau
 * @property string $ngay_xuat_ban
 * @property string $so_bao_dang
 * @property string $tinh_trang_tong_tin
 * @property string $ma_thong_tin
 * @property string $thong_tin_chuyen_tien
 * @property string $thong_tin_khac
 * @property string $id_nguoi_tao
 * @property string $ngay_tao
 * @property string $id_nguoi_chinh_sua
 * @property string $id_nguoi_duyet
 * @property integer $status
 * @property string $da_thanh_toan
 * @property string $tong_tien
 * @property string $ngay_duyet
 * @property string $image_url
 * @property string $ly_do
 *
 * The followings are the available model relations:
 * @property DanhSachLinhVuc $linhVuc
 * @property DanhSachNganh $nganh0
 * @property HinhThucDauThau $hinhThuc
 * @property ThanhVien $idNguoiDuyet
 * @property ThanhVien $idNguoiTao
 */
class FormThongBaoMoiThau extends CActiveRecord
{

    const CHUA_DUOC_DUYET = 0;
    const DA_DUOC_DUYET = 1;
    const KHONG_DUOC_DUYET = 2;
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'form_thong_bao_moi_thau';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('nganh, linh_vuc, hinh_thuc, status', 'numerical', 'integerOnly'=>true),
			array('dia_diem, ten_du_an, ben_moi_thau, dia_diem_ban, tinh_trang_tong_tin, thong_tin_khac, ten_goi_thau', 'length', 'max'=>250),
			array('nguon_von, so_bao_dang, ma_thong_tin, thong_tin_chuyen_tien', 'length', 'max'=>150),
			array('gia_ban, da_thanh_toan, tong_tien', 'length', 'max'=>10),
			array('id_nguoi_tao, id_nguoi_chinh_sua, id_nguoi_duyet', 'length', 'max'=>20),
			array('thoi_gian_bat_dau, thoi_gian_ket_thuc, thoi_gian_dong_thau, ngay_xuat_ban, ngay_tao, ngay_duyet', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, nganh, linh_vuc, dia_diem, ten_du_an, nguon_von, ben_moi_thau, hinh_thuc, thoi_gian_bat_dau, thoi_gian_ket_thuc, dia_diem_ban, gia_ban, thoi_gian_dong_thau, ngay_xuat_ban, so_bao_dang, tinh_trang_tong_tin, ma_thong_tin, thong_tin_chuyen_tien, thong_tin_khac, id_nguoi_tao, ngay_tao, id_nguoi_chinh_sua, id_nguoi_duyet, status, da_thanh_toan, tong_tien, ngay_duyet', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'linhVuc' => array(self::BELONGS_TO, 'DanhSachLinhVuc', 'linh_vuc'),
			'nganh0' => array(self::BELONGS_TO, 'DanhSachNganh', 'nganh'),
			'hinhThuc' => array(self::BELONGS_TO, 'HinhThucDauThau', 'hinh_thuc'),
			'idNguoiDuyet' => array(self::BELONGS_TO, 'ThanhVien', 'id_nguoi_duyet'),
			'idNguoiTao' => array(self::BELONGS_TO, 'ThanhVien', 'id_nguoi_tao'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'ten_goi_thau' => 'Tên gói thầu',
			'nganh' => 'Ngành',
			'linh_vuc' => 'Lĩnh vực',
			'dia_diem' => 'Địa điểm',
			'ten_du_an' => 'Tên dự án',
			'nguon_von' => 'Nguồn vốn',
			'ben_moi_thau' => 'Bên mời thầu',
			'hinh_thuc' => 'Hình thức',
			'thoi_gian_bat_dau' => 'Thời gian bắt đầu bán HSMT',
			'thoi_gian_ket_thuc' => 'Thời gian kết thúc bán HSMT',
			'dia_diem_ban' => 'Địa điểm bán',
			'gia_ban' => 'Giá bán',
			'thoi_gian_dong_thau' => 'Thời gian đóng thầu',
			'ngay_xuat_ban' => 'Ngày xuất bản',
			'so_bao_dang' => 'Số báo đăng',
			'tinh_trang_tong_tin' => 'Tình trạng thông tin',
			'ma_thong_tin' => 'Mã thông tin',
			'thong_tin_chuyen_tien' => 'Thông tin chuyển tiền',
			'thong_tin_khac' => 'Thông tin khác',
			'id_nguoi_tao' => 'Người tạo',
			'ngay_tao' => 'Ngày tạo',
			'id_nguoi_chinh_sua' => 'Người chỉnh sửa',
			'id_nguoi_duyet' => 'Người duyệt',
			'status' => 'Status',
			'da_thanh_toan' => 'Đã thanh toán',
			'tong_tien' => 'Tổng tiền',
			'ngay_duyet' => 'Ngày duyệt',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('nganh',$this->nganh);
		$criteria->compare('linh_vuc',$this->linh_vuc);
		$criteria->compare('dia_diem',$this->dia_diem,true);
		$criteria->compare('ten_du_an',$this->ten_du_an,true);
		$criteria->compare('nguon_von',$this->nguon_von,true);
		$criteria->compare('ben_moi_thau',$this->ben_moi_thau,true);
		$criteria->compare('hinh_thuc',$this->hinh_thuc);
		$criteria->compare('thoi_gian_bat_dau',$this->thoi_gian_bat_dau,true);
		$criteria->compare('thoi_gian_ket_thuc',$this->thoi_gian_ket_thuc,true);
		$criteria->compare('dia_diem_ban',$this->dia_diem_ban,true);
		$criteria->compare('gia_ban',$this->gia_ban,true);
		$criteria->compare('thoi_gian_dong_thau',$this->thoi_gian_dong_thau,true);
		$criteria->compare('ngay_xuat_ban',$this->ngay_xuat_ban,true);
		$criteria->compare('so_bao_dang',$this->so_bao_dang,true);
		$criteria->compare('tinh_trang_tong_tin',$this->tinh_trang_tong_tin,true);
		$criteria->compare('ma_thong_tin',$this->ma_thong_tin,true);
		$criteria->compare('thong_tin_chuyen_tien',$this->thong_tin_chuyen_tien,true);
		$criteria->compare('thong_tin_khac',$this->thong_tin_khac,true);
		$criteria->compare('id_nguoi_tao',$this->id_nguoi_tao,true);
		$criteria->compare('ngay_tao',$this->ngay_tao,true);
		$criteria->compare('id_nguoi_chinh_sua',$this->id_nguoi_chinh_sua,true);
		$criteria->compare('id_nguoi_duyet',$this->id_nguoi_duyet,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('da_thanh_toan',$this->da_thanh_toan,true);
		$criteria->compare('tong_tien',$this->tong_tien,true);
		$criteria->compare('ngay_duyet',$this->ngay_duyet,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
    public function duyet()
    {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id,true);
        $criteria->compare('nganh',$this->nganh);
        $criteria->compare('linh_vuc',$this->linh_vuc);
        $criteria->compare('dia_diem',$this->dia_diem,true);
        $criteria->compare('ten_du_an',$this->ten_du_an,true);
        $criteria->compare('nguon_von',$this->nguon_von,true);
        $criteria->compare('ben_moi_thau',$this->ben_moi_thau,true);
        $criteria->compare('hinh_thuc',$this->hinh_thuc);
        $criteria->compare('thoi_gian_bat_dau',$this->thoi_gian_bat_dau,true);
        $criteria->compare('thoi_gian_ket_thuc',$this->thoi_gian_ket_thuc,true);
        $criteria->compare('dia_diem_ban',$this->dia_diem_ban,true);
        $criteria->compare('gia_ban',$this->gia_ban,true);
        $criteria->compare('thoi_gian_dong_thau',$this->thoi_gian_dong_thau,true);
        $criteria->compare('ngay_xuat_ban',$this->ngay_xuat_ban,true);
        $criteria->compare('so_bao_dang',$this->so_bao_dang,true);
        $criteria->compare('tinh_trang_tong_tin',$this->tinh_trang_tong_tin,true);
        $criteria->compare('ma_thong_tin',$this->ma_thong_tin,true);
        $criteria->compare('thong_tin_chuyen_tien',$this->thong_tin_chuyen_tien,true);
        $criteria->compare('thong_tin_khac',$this->thong_tin_khac,true);
        $criteria->compare('id_nguoi_tao',$this->id_nguoi_tao,true);
        $criteria->compare('ngay_tao',$this->ngay_tao,true);
        $criteria->compare('id_nguoi_chinh_sua',$this->id_nguoi_chinh_sua,true);
        $criteria->compare('id_nguoi_duyet',$this->id_nguoi_duyet,true);
        $criteria->compare('status',0);
        $criteria->compare('da_thanh_toan',$this->da_thanh_toan,true);
        $criteria->compare('tong_tien',$this->tong_tien,true);
        $criteria->compare('ngay_duyet',$this->ngay_duyet,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return FormThongBaoMoiThau the static model class
	 */
    protected function beforeSave()
    {
        $this->thoi_gian_bat_dau = Helper::getDateTime($this->thoi_gian_bat_dau);
        $this->thoi_gian_dong_thau = Helper::getDateTime($this->thoi_gian_dong_thau);
        $this->thoi_gian_ket_thuc= Helper::getDateTime($this->thoi_gian_ket_thuc);
        $this->ngay_xuat_ban= Helper::getDateTime($this->ngay_xuat_ban);
        return parent::beforeSave(); // TODO: Change the autogenerated stub
    }

    public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
